var rowid=null;
var rowhid=null;
var rowpid=null;
var pageSize = 10;
$(document).ready(function(){
	commonSet();
	//表格初始化
	initTable();
	//事件绑定
	eventBind();
});

function commonSet(){
	genDictSelect('transferType','transfer_type','1');
}

function eventBind(){
	//带有分页信息的查询
	$("#queryBtn").click(pageQuery).click();
	//同意弹出层
	$("#agreeBtn").click(showAgreeFormDialog);
	//不同意弹出层
	$("#unagreeBtn").click(showResonFormDialog);
}

function initTable(){
	$('#agreeTable').bootstrapTable({
		onPageChange: function (number, size) {
			pageSize = size;
			query(number, size);
		},
		onCheck:function (row) {
			rowid=row.id;
			rowhid=row.assign_hid;
			rowpid=row.patient_id;
		}
	});
}

//带有分页信息的查询
function pageQuery(){
	query(1, pageSize);
};

function showEditFormDialog(row){
	customRemoteUrlDialog('患者详情','/page/business/patient/view?pId='+row.patient_id,null);
}

//分页查询已接诊
function query(pageNumber, pageSize){
	var queryCondition={
		pageNumber: pageNumber, 
		pageSize: pageSize,
		params:$("#agreeForm").collect()
	}
	$.getApiClient('/transfer/listAgree').setQuery(queryCondition).post().done(function(data){
	    $('#agreeTable').bootstrapTable('load', data.payload);
	});
};
//弹出不通过原因保存
function showResonFormDialog(){
	if(rowid==null){//增加提示
		customTimeOutDialog('信息提示','请选择患者后进行操作',null,1000);
	}else{
		customRemoteUrlDialog('审核','/page/business/transfer/tranReson?tId='+rowid+'&pId='+rowpid,null);
	}
}

//转诊同意弹出框
function showAgreeFormDialog(){
	if(rowid==null){//增加提示
		customTimeOutDialog('信息提示','请选择患者后进行操作',null,1000);
	}else{
		customRemoteUrlDialog('审核通过','/page/business/transfer/receive?hId='+rowhid+'&tId='+rowid+'&pId='+rowpid,null);
	}
}
function showDetailFormDialog(row){
		customRemoteUrlDialog('详情查看','/page/business/transfer/tranDetail?tId='+row.id,null);
}
function operateFormatter(value, row, index) {	
	var operates=[];
	operates.push('<a class="edit" href="javascript:void(0)" title="患者详情"><i class="fa fa-edit"></i>患者详情</a>');
	operates.push('&nbsp;&nbsp;&nbsp;');
	operates.push('<a class="detail" href="javascript:void(0)" title="申请详情"><i class="fa fa-edit"></i>申请详情</a>');
	return operates.join('');
};

operateEvents = {
	'click .edit' : function(e, value, row, index) {
		if(row==null){
			customTimeOutDialog('信息提示','请选择患者',null,2000);
		}
		showEditFormDialog(row);
	},
    'click .detail' : function(e, value, row, index) {
	if(row==null){
		customTimeOutDialog('信息提示','请选择患者',null,2000);
	}
		showDetailFormDialog(row);
    }
};
